
package com.lry.serialize;


public enum SerializerType {

    RPC((byte)0x1,"rpc"),

    FAST_JSON((byte)0x2,"fastJson"),

    HESSION((byte)0x4,"hession"),

    JDK((byte)0x8,"jdk"),

    KRYO((byte)0x16,"kryo");

    private final byte code;

    private final String name;

    SerializerType(final byte code,String name) {
        this.code = code;
        this.name = name;
    }

    public static String getName(byte code){
        return getByCode(code).name;
    }

    /**
     * Gets result code.
     *
     * @param code the code
     * @return the result code
     */
    public static SerializerType getByCode(int code) {
        for (SerializerType b : SerializerType.values()) {
            if (code == b.code) {
                return b;
            }
        }
        throw new IllegalArgumentException("unknown codec:" + code);
    }

    /**
     * Gets result code.
     *
     * @param name the name
     * @return the result code
     */
    public static SerializerType getByName(String name) {
        for (SerializerType b : SerializerType.values()) {
            if (b.name().equalsIgnoreCase(name)) {
                return b;
            }
        }
        throw new IllegalArgumentException("unknown codec:" + name);
    }

    /**
     * Gets code.
     *
     * @return the code
     */
    public byte getCode() {
        return code;
    }
}
